package com.shengde.jinwawaforleader.model.homePage;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.shengde.jinwawaforleader.R;
import com.shengde.jinwawaforleader.base.BaseActivity;
import com.shengde.jinwawaforleader.bean.User;
import com.shengde.jinwawaforleader.network.BasexUtilsProtocol;
import com.shengde.jinwawaforleader.network.protocolbean.ProShowClickGood;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * @author 鞠永强
 * @version $Rev$
 * @time 2017/2/17 0017 10:13
 * @des ${编辑第三方链接和分享的标题和内容}
 * @updateAuthor $Author$
 * @updateDate $Date$
 * @updateDes ${TODO}
 */

public class EditDetailActivity extends BaseActivity {
    private TextView tv_back;
    private TextView tv_title;
    private TextView fill_add;
    private EditText edt_content;
    private int type;

    @Override
    public void onRoot(Bundle savedInstanceState) {
        setContentView(R.layout.activity_edit_detail);
    }

    @Override
    public void initView() {
        edt_content = (EditText) findViewById(R.id.edt_content);
        tv_back = (TextView) findViewById(R.id.tv_back);
        tv_title = (TextView) findViewById(R.id.tv_title);
        fill_add = (TextView) findViewById(R.id.fill_add);
    }

    @Override
    public void initData() {
        tv_title.setText(getString(R.string.edit_three_link));
        fill_add.setText(getString(R.string.save));
        type = getIntent().getIntExtra("type", 0);
    }

    @Override
    public void initListener() {
        tv_back.setOnClickListener(this);
        fill_add.setOnClickListener(this);
    }

    @Override
    public void onWidgetClick(View view) {
        switch (view.getId()) {
            case R.id.tv_back:
                finish();
                break;
            case R.id.fill_add:

                if (type == 1) {
                    showSaveUrl();

                } else if (type == 2) {

                } else if (type == 3) {

                }
                break;
            default:
                break;
        }
    }

    /**
     * 上传第三方 链接
     */
    private void showSaveUrl() {
        RequestParams params = BasexUtilsProtocol.sendHttpRequest(this, "/synopsis/synopsisAdd");
        params.addParameter("type", 1);
        params.addParameter("schoolid", User.getSchoolId(this));
        params.addParameter("url", edt_content.getText().toString().trim());
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                ProShowClickGood proShowClick = new Gson().fromJson(result, ProShowClickGood.class);
                if (proShowClick.getCode() == 0) {
                    Toast.makeText(EditDetailActivity.this, "保存成功", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {
                BasexUtilsProtocol.dialog.dismiss();
            }
        });
    }
}
